package com.company.project.controller.ldjsc.weather;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.company.project.entity.ldjsc.weather.ZyCityCodeEntity;
import com.company.project.service.ldjsc.weather.ZyCityCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;




/**
 * 城市代码
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2025-07-21 15:24:06
 */
@Controller
@RequestMapping("/sxzy")
public class ZyCityCodeController {
    @Autowired
    private ZyCityCodeService zyCityCodeService;

    /**
     * 五天天气城市名称列表
     */
    @GetMapping("/all/zyCityCode")
    @ResponseBody
    public DataResult allCityCode() {
        return DataResult.success(zyCityCodeService.list());
    }

    /**
    * 跳转到页面
    */
    @GetMapping("/index/zyCityCode")
    public String zyCityCode() {
        return "zycitycode/list";
    }


    @ApiOperation(value = "查询分页数据")
    @PostMapping("zyCityCode/listByPage")
    @SaCheckPermission("zyCityCode:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody ZyCityCodeEntity zyCityCode){
        LambdaQueryWrapper<ZyCityCodeEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        queryWrapper.eq(zyCityCode.getId() != null, ZyCityCodeEntity::getId, zyCityCode.getId());
        queryWrapper.orderByDesc(ZyCityCodeEntity::getId);
        IPage<ZyCityCodeEntity> iPage = zyCityCodeService.page(zyCityCode.getQueryPage(), queryWrapper);
        return DataResult.success(iPage);
    }


    @ApiOperation(value = "新增")
    @PostMapping("zyCityCode/add")
    @SaCheckPermission("zyCityCode:add")
    @ResponseBody
    public DataResult add(@RequestBody ZyCityCodeEntity zyCityCode){
            zyCityCodeService.save(zyCityCode);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("zyCityCode/delete")
    @SaCheckPermission("zyCityCode:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
            zyCityCodeService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("zyCityCode/update")
    @SaCheckPermission("zyCityCode:update")
    @ResponseBody
    public DataResult update(@RequestBody ZyCityCodeEntity zyCityCode){
            zyCityCodeService.updateById(zyCityCode);
        return DataResult.success();
    }



}
